const express = require('express');
const router = express.Router();
const { getUserProfile, getMyFavorites, createFavorite, updateUserProfile, getGasCardInfo, handleRechargeGasCard, handleGetRechargeRecords, handleGetUserCoupons, handleReceiveCoupon, handleGetCouponUsageRecords, getUserInfo, handleGetRecommendationQRCode, handleGetRecommendationRecords, handleSubmitMerchantApplication, handleGetMerchantApplicationStatus, handleGetUserOrders, handleGetOrderDetail, handleCancelOrder, handleConfirmReceipt } = require('../controllers/userController');
const { authMiddleware, merchantApplyAccess } = require('../middleware/authMiddleware');
const { logout } = require('../controllers/authController');

// 用户信息接口
router.get('/profile', authMiddleware, getUserProfile);
router.get('/info', authMiddleware, getUserInfo);
router.put('/profile', authMiddleware, updateUserProfile);

// 收藏相关接口
router.get('/favorites', authMiddleware, getMyFavorites);
router.post('/favorites', authMiddleware, createFavorite);

// 加油卡相关路由
router.get('/gas-card', authMiddleware, getGasCardInfo);
router.post('/gas-card/recharge', authMiddleware, handleRechargeGasCard);
router.get('/gas-card/recharge-records', authMiddleware, handleGetRechargeRecords);

// 优惠券相关路由
router.get('/coupons', authMiddleware, handleGetUserCoupons);
router.post('/coupons/receive', authMiddleware, handleReceiveCoupon);
router.get('/coupons/usage-records', authMiddleware, handleGetCouponUsageRecords);

// 订单相关路由
router.get('/orders', authMiddleware, handleGetUserOrders);
router.get('/orders/:id', authMiddleware, handleGetOrderDetail);
router.post('/orders/:id/cancel', authMiddleware, handleCancelOrder);
router.post('/orders/:id/confirm', authMiddleware, handleConfirmReceipt);

// 推荐相关路由
router.get('/recommendation/qrcode', authMiddleware, handleGetRecommendationQRCode);
router.get('/recommendation/records', authMiddleware, handleGetRecommendationRecords);

// 商家入驻相关路由 - 使用merchantApplyAccess中间件允许用户和商家角色访问
router.post('/merchant/apply', merchantApplyAccess, handleSubmitMerchantApplication);
router.get('/merchant/status', merchantApplyAccess, handleGetMerchantApplicationStatus);
router.get('/merchant/apply/status', merchantApplyAccess, handleGetMerchantApplicationStatus); // 添加兼容前端的路由

// 用户登出路由
router.post('/logout', authMiddleware, logout);

module.exports = router;